﻿/*********************
 *  采集端与云端的TCP数据报文
 *  内部报文信息
 * 
 * 
 * 
 * ******************/

using GsOrganization.Common.Extend;
using System;
using System.Text;

namespace GsOrganization.TcpPacket
{
    public class Header:IHeader
    {
        public ushort CommandId { get; set; }
        public ushort MessageLength { get; set; }
        public int TimeStamp { get; set; }

        public Header()
        { }

        public int GetTimeRemain()
        {
            return Math.Abs(TimeStamp - DateTimeExtend.GetTimeStampS());
        }

        public Header(byte[] bsMessage, int index)
        {
            CommandId = bsMessage.Bytes2UShort(index);
            MessageLength = bsMessage.Bytes2UShort(index + 2);
            TimeStamp = bsMessage.Bytes2Int(index + 4);
        }

        public byte[] ToBytes()
        {
            byte[] bs = new byte[8];
            CommandId.UShort2Bytes().CopyTo(bs,0);
            MessageLength.UShort2Bytes().CopyTo(bs,2);
            TimeStamp.Int2Bytes().CopyTo(bs, 4);
            return bs;
        }
    }
}